package cn.itcast.controller;

import cn.itcast.pojo.Result;
import cn.itcast.pojo.Student;
import cn.itcast.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/students")
@Slf4j
public class StudentController {
    @Autowired
    private StudentService studentService;

    //4.1学员列表查询
    @GetMapping
    public Result search(
            String name,
            Integer degree,
            Integer clazzId,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pageSize
    ) {
        return studentService.search(name, degree, clazzId, page, pageSize);
    }

    //4.2批量删除学员
    @DeleteMapping("/{ids}")
    public Result deleteById(@PathVariable List<Integer> ids) {
        return studentService.deleteByIdsStudent(ids);
    }

    //4.3添加学员
    @PostMapping
    public Result insertStudent(@RequestBody Student student) {
        return studentService.insertStudent(student);
    }

    //4.4根据id查询学员
    @GetMapping("/{id}")
    public Result selectById(@PathVariable Integer id) {
        return studentService.selectById(id);
    }

    //4.5修改学员
    @PutMapping
    public Result updateStudent(@RequestBody Student student) {
        return studentService.updateStudent(student);
    }

    //4.6违纪处理
    @PutMapping("/violation/{id}/{score}")
    public Result violation(@PathVariable Integer id, @PathVariable Integer score) {
        return studentService.violation(id, score);
    }

}
